<template>
  <div class="head-container">
    <!-- 搜索 -->
    <div v-show="sup_this.searchToggle">
      <el-select v-model="paramBean.taskStatusList" clearable filterable multiple placeholder="请选择任务状态" style="width: 240px;">
        <el-option v-for="item in dicts.bus_task_status" :key="item.id" :label="item.dictName" :value="item.dictCode"/>
      </el-select>
      <el-input v-model="paramBean.taskName" clearable placeholder="输入名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="sup_this.toQuery"/>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="sup_this.toQuery">搜索</el-button>
      <el-button class="filter-item" size="mini" type="warning" icon="el-icon-refresh-left" @click="sup_this.resetQuery()">重置</el-button>
    </div>
    <div class="crud-opts">
      <el-button
        v-loading="taskLoading"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-video-play"
        @click="doTaskBegin">开始</el-button>
      <el-button
        v-loading="taskLoading"
        class="filter-item"
        size="mini"
        type="warning"
        icon="el-icon-video-pause"
        @click="doTaskPause">暂停</el-button>
      <el-button
        v-loading="taskLoading"
        class="filter-item"
        size="mini"
        type="danger"
        icon="el-icon-video-pause"
        @click="doTaskSuspend">中断</el-button>
      <el-button
        v-loading="taskLoading"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-video-play"
        @click="doTaskResume">继续</el-button>
      <el-button
        v-loading="taskLoading"
        class="filter-item"
        size="mini"
        type="success"
        icon="el-icon-check"
        @click="doTaskEnd">完工</el-button>
      <el-button
        v-loading="taskLoading"
        class="filter-item"
        size="mini"
        type="warning"
        icon="el-icon-check"
        @click="doTaskForceEnd">强制完工</el-button>
    </div>
  </div>
</template>

<script>
import task from '@/api/crm/Task'

export default {
  components: { },
  dictTypes: ['bus_task_status'],
  props: {
    paramBean: {
      type: Object,
      required: true
    },
    sup_this: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      taskLoading: false
    }
  },
  methods: {
    refreshClick() {
      this.sup_this.init()
    },
    searchClick() {
      this.sup_this.toggleSearch()
    },
    beforeCreate() {
    },
    doTaskBegin() {
      this.taskCommonProcess('doTaskBegin', '开始')
    },
    doTaskPause() {
      this.taskCommonProcess('doTaskPause', '暂停')
    },
    doTaskSuspend() {
      this.taskCommonProcess('doTaskSuspend', '中断')
    },
    doTaskResume() {
      this.taskCommonProcess('doTaskResume', '继续')
    },
    doTaskEnd() {
      this.taskCommonProcess('doTaskEnd', '完工')
    },
    doTaskForceEnd() {
      this.taskCommonProcess('doTaskForceEnd', '强制完工')
    },
    taskCommonProcess(postUrl, btnName) {
      const _this = this.sup_this
      const selectIds = _this.getSelectMainIds()
      if (selectIds.length === 0) {
        _this.$message({
          message: '请选择记录',
          type: 'warning'
        })
        return
      }
      _this.$confirm('确认要' + btnName + '选中的记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        _this.taskLoading = true
        const data = { idList: selectIds }
        task.postRequestByName(postUrl, data).then(res => {
          _this.taskLoading = false
          _this.init()
        }).catch(err => {
          _this.taskLoading = false
          console.log(err)
        })
      })
    }
  }
}
</script>
